{"componentChunkName":"component---src-templates-post-jsx","path":"/[CS]연결리스트/","result":{"data":{"site":{"siteMetadata":{"title":"SUbbb"}},"markdownRemark":{"id":"5b487c3d-e474-5a07-a26c-fc8c7d7cab22","excerpt":"🧷 연결 리스트 (Linked List) 연속적인 메모리 위치에 저장되지 않는 선형 데이터 구조로, 포인터를 사용해 연결된다. 각 노드는 데이터 필드와 다음 노드에 대한 참조를 포함하는 노드로 구성된다. 🪚 왜 사용하나? 배열은 비슷한 유형의 선형 데이터를 저장하는데 사용할 수 있지만 제한 사항이 있다. 배열의 크기는 고정적이기에 미리 저장될 요소의 수에…","html":"<h2>🧷 연결 리스트 (Linked List)</h2>\n<img src='https://www.geeksforgeeks.org/wp-content/uploads/gq/2013/03/Linkedlist.png' width='80%'>\n<p>연속적인 메모리 위치에 저장되지 않는 <strong>선형 데이터 구조</strong>로, 포인터를 사용해 연결된다. 각 노드는 <strong>데이터 필드</strong>와 <strong>다음 노드에 대한 참조</strong>를 포함하는 노드로 구성된다.</p>\n<h3>🪚 왜 사용하나?</h3>\n<p>배열은 비슷한 유형의 선형 데이터를 저장하는데 사용할 수 있지만 제한 사항이 있다.</p>\n<ul>\n<li>배열의 크기는 고정적이기에 미리 저장될 요소의 수에 대한 정보가 필요하다.</li>\n<li>새로운 요소를 삽입하는 것은 비용이 많이 발생한다. (공간을 할당하고, 기존 요소를 전부 이동)</li>\n</ul>\n<h3>🪚 장점</h3>\n<ul>\n<li>크기가 동적이다.</li>\n<li>삽입, 삭제가 용이하다.</li>\n</ul>\n<h3>🪚 단점</h3>\n<ul>\n<li>임의로 액세스를 허용할 수 없다, 즉 첫 번째 노드부터 순차적으로 요소에 접근해야 한다. (이진 탐색 불가능)</li>\n<li>포인터의 여분의 메로리 공간이 목록의 각 요소마다 필요하다.</li>\n</ul>\n<h3>🪚 Single Linked List</h3>\n<deckgo-highlight-code language=\"java\" terminal=\"carbon\" theme=\"a11y-dark\" line-numbers=\"true\"  >\n          <code slot=\"code\">import java.util.*;\n\nclass Node {\n  int data;\n  Node next;\n\n  Node(int data) {\n    this.data = data;\n    next = null;\n  }\n}\n\nclass LinkedList {\n  Node head;\n\n  public void printList() {\n    Node n = head;\n\n    while (n != null) {\n      System.out.println(n.data + &quot; &quot;);\n      n = n.next;\n    }\n  }\n\n  // 노드 추가\n  public void push(Node n) {\n    Node h = head;\n\n    if (head == null) {\n      head = n;\n      return;\n    }\n\n    while (h.next != null) {\n      h = h.next;\n    }\n\n    h.next = n;\n  }\n\n  // 특정 노드 뒤에 노드 추가\n  public void push(Node n, int insertAt) {\n    Node h = head;\n\n    if (head == null) {\n      head = n;\n      return;\n    }\n\n    while (h.data != insertAt) {\n      h = h.next;\n    }\n\n    Node tmp = null;\n    h.next = tmp;\n    h.next = n;\n    n.next = tmp;\n  }\n}\n\nclass Main {\n  public static void main(String[] args) {\n    LinkedList ll = new LinkedList();\n\n    for (int i = 1; i &lt; 4; i++) {\n      ll.push(new Node(i));\n    }\n\n    ll.printList();\n  }\n}</code>\n        </deckgo-highlight-code>\n<hr>\n<h2>📕 참고</h2>\n<ul>\n<li><a href=\"https://gyoogle.dev/blog/computer-science/data-structure/Linked%20List.html\">Tech Interview for developer</a></li>\n<li><a href=\"https://github.com/JaeYeopHan/Interview_Question_for_Beginner/tree/master/DataStructure#array-vs-linked-list\">JaeYeopHan/Interview<em>Question</em>for_Beginner</a></li>\n</ul>","frontmatter":{"title":"📂 연결 리스트 (Linked List)","date":"May 18, 2022","update":"May 18, 2022","tags":["개발상식","Java","연결리스트"],"series":"📂 Computer Science"},"fields":{"slug":"/[CS]연결리스트/","readingTime":{"minutes":2.31}}},"seriesList":{"edges":[{"node":{"id":"3fe44622-13ba-589a-bbe8-01581ea7eb50","fields":{"slug":"/[CS]배열/"},"frontmatter":{"title":"📂 배열 (Array)"}}},{"node":{"id":"5b487c3d-e474-5a07-a26c-fc8c7d7cab22","fields":{"slug":"/[CS]연결리스트/"},"frontmatter":{"title":"📂 연결 리스트 (Linked List)"}}},{"node":{"id":"57149a6b-c730-5ce4-a3c5-9cea44979c8c","fields":{"slug":"/[CS]Array&ArrayList&LinkedList/"},"frontmatter":{"title":"📂 Array vs. ArrayList vs. LinkedList"}}},{"node":{"id":"28dac540-50bf-57df-afd9-9561888e8889","fields":{"slug":"/[CS]Stack&Queue/"},"frontmatter":{"title":"📂 Stack & Queue"}}},{"node":{"id":"4c2e96a9-4c71-57e3-b8e4-220b2cdf3002","fields":{"slug":"/[CS]Heap/"},"frontmatter":{"title":"📂 Heap"}}},{"node":{"id":"44f6bf8c-3235-5ff7-9d5f-f7c816218acb","fields":{"slug":"/[CS]Trie/"},"frontmatter":{"title":"📂 Trie(트라이)"}}},{"node":{"id":"81b508c5-2689-54e4-b36f-2e8bd07e2297","fields":{"slug":"/[CS]Tree/"},"frontmatter":{"title":"📂 Tree(트리)"}}},{"node":{"id":"2efb6036-05bf-594e-b9b5-03e399be6f78","fields":{"slug":"/[CS]이진탐색트리/"},"frontmatter":{"title":"📂 이진탐색트리(Binary Search Tree)"}}},{"node":{"id":"d1ac08af-f215-5176-9cd8-df1760f4ff7e","fields":{"slug":"/[CS]BTree&B+Tree/"},"frontmatter":{"title":"📂 B Tree & B+ Tree"}}}]},"previous":{"fields":{"slug":"/[CS]배열/"},"frontmatter":{"title":"📂 배열 (Array)"}},"next":{"fields":{"slug":"/[Programmers]17676/"},"frontmatter":{"title":"👩‍💻 17676. 추석 트래픽"}}},"pageContext":{"id":"5b487c3d-e474-5a07-a26c-fc8c7d7cab22","series":"📂 Computer Science","previousPostId":"3fe44622-13ba-589a-bbe8-01581ea7eb50","nextPostId":"3a56fa21-2504-54dd-a1f3-9990d0d6d598"}},"staticQueryHashes":[]}